import { createRouter, createWebHistory } from 'vue-router'
const home = () => import('@/views/home/home.vue')
const testbankdetail = () => import('@/views/home/category/testbankdetail/testbankdetail.vue')
const testexplaindetail = () =>
  import('@/views/home/category/explaincategory/explaincategorydetail/explaincategorydetail.vue')

const adminskilllist = () => import('@/views/adminskill/adminskilllist/adminskilllist.vue')

const adminskilldetail = () => import('@/views/adminskill/adminskilldetail/adminskilldetail.vue')
const explainlist = () => import('@/views/explain/explainlist/explainlist.vue')
const explaindetail = () => import('@/views/explain/explaindetail/explaindetail.vue')
const about = () => import('@/views/about/about.vue')
const login = () => import('@/views/about/login/login.vue')
const aboutusdetail = () => import('@/views/about/aboutus/aboutusdetail.vue')
const news = () => import('@/views/news/newslist/news.vue')
const newsdetail = () => import('@/views/news/newsdetail/newsdetail.vue')
const download = () => import('@/views/testpaper/testpaper.vue')
const share = () => import('@/views/share/sharelist/sharelist.vue')
const sharedetail = () => import('@/views/share/sharedetail/sharedetail.vue')
const searchlist = () => import('@/views/home/search/searchlist.vue')
const notfound = () => import('@/views/notfound/notfound.vue')


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
   
    {
      path: '/',

      name: 'home',
      component: home,
       meta: { title: '首页' }
    },
     {
      path: '/home',
      redirect: '/',
    },
    {
      path: '/testbankdetail/:iid',

      name: 'testbankdetail',
      component: testbankdetail,
             meta: { title: '行测题库' }

    },

    {
      path: '/testexplaindetail/:nid',
      name: 'testexplaindetail',
      component: testexplaindetail,
             meta: { title: '申论题库' }

    },

    {
      path: '/adminskilllist',
      name: 'adminskilllist',

      component: adminskilllist,
             meta: { title: '行测技巧' }

    },

    {
      path: '/adminskilldetail/:iid',
      name: 'adminskilldetail',

      component: adminskilldetail,
             meta: { title: '行测技巧详情' }

    },

    {
      path: '/explain',
      name: 'explainlist',

      component: explainlist,
             meta: { title: '申论技巧' }

    },
    {
      path: '/explaindetail/:iid',
      name: 'explaindetail',

      component: explaindetail,
             meta: { title: '申论技巧详情' }

    },
    {
      path: '/about',
      name: 'about',

      component: about,
             meta: { title: '我的' }

    },
    {
      path: '/login',
      name: 'login',

      component: login,
             meta: { title: '登陆注册' }

    },
    {
      path: '/aboutusdetail',
      name: 'aboutusdetail',

      component: aboutusdetail,
             meta: { title: '关于我们' }

    },
    {
      path: '/news',
      name: 'news',

      component: news,
             meta: { title: '最新时政' }

    },
    {
      path: '/newsdetail/:iid',
      name: 'newsdetail',

      component: newsdetail,
             meta: { title: '时政详情' }

    },
    {
      path: '/download',
      name: 'download',

      component: download,
             meta: { title: '下载文件' }

    },

    {
      path: '/share',
      name: 'share',

      component: share,
             meta: { title: '经验分享' }

    },
    {
      path: '/sharedetail/:id',
      name: 'sharedetail',

      component: sharedetail,
             meta: { title: '分享详情' }

    },
    {
      path: '/searchlist',
      name: 'searchlist',

      component: searchlist,
             meta: { title: '搜索' }

    },
    //404页面处理
      {
      path: '/:pathMatch(.*)*',
      name: 'notfound',
      component:notfound
    }
  ],
})
// 可选：全局前置守卫设置标题
router.beforeEach((to, from, next) => {
  document.title = to.meta.title ? `${to.meta.title} - 省考技巧网` : '省考技巧网'
  next()
})
 

export default router
